package tongwentongshu.com.app.presenter;

import android.support.v4.util.ArrayMap;

import java.util.Map;

import tongwentongshu.com.app.bean.AppItem;
import tongwentongshu.com.app.bean.MessageBean;
import tongwentongshu.com.app.contract.MyMessageListContract;
import tongwentongshu.com.app.db.Cache;
import tongwentongshu.com.app.network.ResponseSubscriber;
import tongwentongshu.com.app.update.UpdateFractory;

/**
 * Created by XiongBin on 2017/7/28.
 */

public class MyMessageListPresenter implements MyMessageListContract.Presenter {
    MyMessageListContract.View myMessageListView;
    private Map<String, String> map;

    public MyMessageListPresenter(MyMessageListContract.View myMessageListView) {
        this.myMessageListView = myMessageListView;
    }


    @Override
    public void getMyMessageList(String message_type) {
        map = new ArrayMap<>();
        map.put("token", Cache.getToken());
        map.put("message_type", message_type);
        map.put("pagesize", "50");

        UpdateFractory.getBuild()
                .name("MessageListCall")
                .map(map)
                .build()
                .execute(new ResponseSubscriber<MessageBean>() {

                    @Override
                    public void onFailure(Throwable e) {
                        e.printStackTrace();
                    }

                    @Override
                    public void onSuccess(MessageBean bean, String msg) {
                        myMessageListView.onSuccess(bean);
                    }

                    @Override
                    public void onCompleted() {
                        super.onCompleted();
                    }
                });
    }
    @Override
    public void chengeMessage(String message_id) {
        map = new ArrayMap<>();
        map.put("messid", message_id);

        UpdateFractory.getBuild()
                .name("UpdateMessageCall")
                .map(map)
                .build()
                .execute(new ResponseSubscriber<AppItem>() {

                    @Override
                    public void onFailure(Throwable e) {
                        e.printStackTrace();
                    }

                    @Override
                    public void onSuccess(AppItem bean, String msg) {
                    }

                    @Override
                    public void onCompleted() {
                        super.onCompleted();
                    }
                });
    }
}
